Ext.ns('App.login');
App.login.LoginWindow = Ext.extend(Ext.Panel, {
	constructor : function(_config) {

		if (_config == null) {
			_config = {};
		}

		Ext.apply(this, _config);

		App.login.LoginWindow.superclass.constructor.call(this, _config);

		Ext.QuickTips.init();

		this.pWidth = 1024;
		this.pHeight = 768;

		this.viewW = this.pWidth - 60;

		Ext.get("dddd").setWidth(this.viewW);

		this.viewH = this.pHeight - 20;

		this.form = new Ext.FormPanel( {
			renderTo : 'dddd',
			id : 'iCLoginPanel',
			border : false,
			layout : 'absolute',
			width : this.viewW,
			height : this.viewH - 120,
			margins : 0,
			frame : true,
			html : "<img src='./commons/images/768.png' height='100%' width='100%'/>",
			items : [ {
				xtype : 'textfield',
				x : 455,
				y : 310,
				name : 'userName',
				minLength : 2,
				maxLength : 30,
				maxLengthText : '用户名最大输入30个字符',
				width : 110,
				allowBlank : false,
				blankText : '用户名不能为空',
				anchor : '63%'
			}, {
				xtype : 'textfield',
				x : 455,
				y : 340,
				name : 'password',
				inputType : 'password',
				minLength : 3,
				maxLength : 20,
				maxLengthText : '密码最大输入20个字符',
				width : 110,
				allowBlank : false,
				blankText : '密码不能为空',
				anchor : '63%'
			}, new Ext.ux.ImageButton( {
				imgPath : './commons/images/login.png',
				x : 370,
				y : 380,
				imgWidth : 110,
				imgHeight : 25,
				tooltip : '登录',
				handler : iCLogin
			}), new Ext.ux.ImageButton( {
				imgPath : './commons/images/clear.png',
				x : 530,
				y : 380,
				imgWidth : 110,
				imgHeight : 25,
				tooltip : '重置',
				handler : function() {
					Ext.getCmp('iCLoginPanel').getForm().reset();
				}
			}) ],
			listeners : {
				'render' : function(panel) {
					panel.body.on('keypress', function(e) {
						if (e.keyCode == 13)
							iCLogin();
					})
				}
			}
		});

	}
})

function iCLogin() {
	var loginForm = Ext.getCmp('iCLoginPanel').getForm();
	if (loginForm.isValid()) {
		loginForm.submit( {
			waitTitle : '提示',
			waitMsg : '正在登录……',
			url : 'security/login',
			method : 'post',
			success : function(form, action) {
				if (action.result.success) {
					window.location.href = 'main.jsp';
				} else {
					Ext.Msg.alert('提示', action.result.info);
				}
			},
			failure : function(form, action) {
				Ext.Msg.alert('提示', action.result.info);
			}
		})
	}
}
